package com.zl.tby.screen.vo.forest;

import com.zl.tby.core.base.util.ToolsUtil;
import lombok.Data;

import java.math.BigDecimal;
import java.time.Year;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;

/**
 * 火情监测通用bean
 * @author changpeng
 * @version 1.0
 * @since 2024/8/19 10:22
 */
@Data
public class TbyForestScreenBean {
    /**火险等级*/
    private String fireRating;
    /**天气*/
    private String weather;
    /**气温*/
    private BigDecimal temperature;
    /**温度类型*/
    private Integer weatherType;
    /**aqi*/
    private String aqi;
    /**风向*/
    private String windDirection;
    /**湿度*/
    private BigDecimal humidity;
    /**紫外线等级(1:弱 2：较弱 3：中等 4：较强 5强)*/
    private Integer ultravioletRays;
    /**安全无火灾年数*/
    private Long secureYear;
    private Integer yearOne;
    private Integer yearTwo;
    /**安全无火灾天数*/
    private Long secureDay;
    private Integer dayOne;
    private Integer dayTwo;
    private Integer dayThree;

    /**填充距今多少年多少天*/
    public void fillYearAndDay(Date fromDate) {
        if (fromDate == null) {
            return;
        }
        String temp = ToolsUtil.dateUtil2String(fromDate, "yyyy-MM-dd") + " 00:00:00";
        fromDate = ToolsUtil.dateString2Util(temp, "yyyy-MM-dd HH:mm:ss");
        if (fromDate.getTime() >= new Date().getTime()) {
            return;
        }
        temp = ToolsUtil.dateUtil2String(new Date(System.currentTimeMillis()), "yyyy-MM-dd") + " 00:00:00";
        Date toDate = ToolsUtil.dateString2Util(temp, "yyyy-MM-dd HH:mm:ss");
        int yearDay = Year.of(toDate.getYear()).length();
        Calendar from = Calendar.getInstance();
        from.setTime(fromDate);
        Calendar to = Calendar.getInstance();
        to.setTime(toDate);
        long years = ChronoUnit.YEARS.between(fromDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), toDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
        int fromDay = from.get(Calendar.DAY_OF_YEAR);
        int toDay = to.get(Calendar.DAY_OF_YEAR);
        int day = toDay  - fromDay;
        if (day < 0) {
            day = yearDay + day;
        }
        this.setSecureDay((long) day);
        this.setSecureYear(years);
        try {
            char[] yearChar = ToolsUtil.fillLength(this.getSecureYear() + "", 2).toCharArray();
            char[] dayChar = ToolsUtil.fillLength(this.getSecureDay() + "", 3).toCharArray();
            this.yearOne = Integer.parseInt(yearChar[0] + "");
            this.yearTwo = Integer.parseInt(yearChar[1] + "");
            this.dayOne = Integer.parseInt(dayChar[0] + "");
            this.dayTwo = Integer.parseInt(dayChar[1] + "");
            this.dayThree = Integer.parseInt(dayChar[2] + "");
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}
